'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:AdministratorAdminJyzCtrl
 * @description
 * # AdministratorAdminJyzCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('AdministratorAdminJyzCtrl', function ($scope, openApi, Util, $location, $routeParams, FormSubmit) {
        //获取证件信息列表
        var id = $scope.process_id = $routeParams.id
        $scope.getChoosecertId = function () {
            Util.saveSelectLists($scope.param.detailList);
            Util.savaParamForReview($scope.param, id);
            $location.path("administrator/chooseinfo/jyz");
        };
        // 删除证件信息列表
        $scope.deletedItem = function (index) {
            $scope.param.detailList.splice(index, 1);
            $scope.index = -1;
            Util.saveSelectLists($scope.param.detailList);
        };
        var getAllpkIds = function () {
            var pkIds = [],
                pkIdsStr;
            $scope.param.detailList.forEach(function (item, index) {
                pkIds.push(item.pkId);
            });
            pkIdsStr = pkIds.join(",");
            return pkIdsStr;
        }
        $scope.submit = function (operationId) {

            $scope.param.sealIds = getAllpkIds();
            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.borrowSeal;
            options.param = angular.copy($scope.param, {});
            delete options.param.detailList
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.borrowReason) {
                Util.Toast("请填写借印事由");
                return;
            }
            if (!$scope.param.returnDate) {
                Util.Toast("请选择预计归还日期");
                return;
            }
            if ($scope.param.detailList.length < 1) {
                Util.Toast("请选择证件信息");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        $scope.swipe = function (index) {
            $scope.index = index;
        }
        $scope.resetlist = function (index) {
            $scope.index = -1;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                // 获取选择页面返回的数据并且合并到参数中
                var selectLists;
                selectLists = Util.getSelectLists();
                $scope.param.detailList = selectLists || $scope.param.detailList || [];
            });
        };
        // 初始化
        init();

    });